package com.gap.dam.module.system.login;

import com.gap.dam.common.anno.NoNeedLogin;
import com.gap.dam.common.anno.NoValidPrivilege;
import com.gap.dam.common.anno.OperateLog;
import com.gap.dam.common.base.ResponseDTO;
import com.gap.dam.common.login.RequestTokenBO;
import com.gap.dam.constant.SwaggerTagConst;
import com.gap.dam.module.system.employee.domain.dto.EmployeeLoginFormDTO;
import com.gap.dam.module.system.login.domain.LoginDetailVO;
import com.gap.dam.util.RequestTokenUtil;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletRequest;
import javax.validation.Valid;

@RestController
@Api(tags = {SwaggerTagConst.Admin.MANAGER_USER_LOGIN})
@OperateLog
public class LoginController {
    @Autowired
    private LoginService loginService;

    @PostMapping("/session/login")
    @ApiOperation(value = "登录", notes = "登录")
    @NoNeedLogin
    public ResponseDTO<LoginDetailVO> login(@Valid @RequestBody EmployeeLoginFormDTO loginForm, HttpServletRequest request) {
        return loginService.login(loginForm, request);
    }

    @GetMapping("/session/get")
    @ApiOperation(value = "获取session", notes = "获取session")
    @NoValidPrivilege
    public ResponseDTO<LoginDetailVO> getSession() {
        RequestTokenBO requestUser = RequestTokenUtil.getRequestUser();
        return ResponseDTO.succData(loginService.getSession(requestUser));
    }
}
